import scrapy
import json
from bixin.items import BixinItem
from scrapy_redis.spiders import RedisSpider
from scrapy.http import Request
class GoSpider(RedisSpider):
    name = 'go'
    # allowed_domains = ['bixin.com']
    # start_urls = ['http://bixin.com/']
    redis_key = 'www:start_urls'
    # url ='https://jingjia.wowyep.com/peiwan/getList'

    def parse(self, response):
        for i in range(1,250):
            data = {
                'page': str(i),
                'page_size': '15',
                'class_id': '0',
                'sex': '',
                'attribute':'',
                'order': 'price',
                'sort': '',
                'termtyp': 'client',
                'vr': '1.0.0'
            }               
            yield scrapy.FormRequest(url=response.url,formdata=data,callback=self.zhix,dont_filter=True)
    def zhix(self,response):
        bx = BixinItem()
        jd = json.loads(response.text)
        for i in jd.get('data').get('list'):
            name = i.get('nickname')
            jiage = i.get('price')
            url = i.get('mp3_path')
            uid = i.get('uid')
            tu = i.get('avatar')
            bx['name'] =name
            bx['jiage'] = jiage
            bx['url']= url
            bx['uid'] = uid
            bx['tu']=tu
            yield bx

